module etc.dleveldb.cache;


import deimos.leveldb.c;

import std.exception;


abstract static class Cache
{
    ~this()
    {
        if(isValid){
            leveldb_cache_destroy(this._cache);
        }
        this._cache = null;
    }
    @property:
    bool isValid() const
    {
        return (this._cache !is null);
    }
    package:
    @property
    inout(leveldb_cache_t*) ptr() inout
    {
        return this._cache;
    }

    protected:
    leveldb_cache_t*  _cache;
}

static class LRU : Cache
{
    this(size_t capacity)
    {
        this._cache = leveldb_cache_create_lru(capacity);
        enforce(this._cache !is null, "Failed to create LRU cache");
    }

}